package com.shangjinrong.controller.site;

import com.shangjinrong.domain.Lend;
import com.shangjinrong.result.R;
import com.shangjinrong.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Naruto
 */

@RestController
@CrossOrigin
@RequestMapping("site/lend")
public class SiteLendController {
    @Autowired
    private LendService lendService;

    @GetMapping("getLendList")
    public R getLendList() {
        List<Lend> lendList = lendService.getLendList();

        return R.ok().data("lendList", lendList);
    }

    @GetMapping("show/{id}")
    public R show(@PathVariable Long id) {
        Map<String, Object> lendDetail = lendService.getLendDetail(id);

        return R.ok().message("获取标的详情成功(●'◡'●)(●'◡'●)(●'◡'●)").data("list", lendDetail);
    }
    //计算投资收益
    @GetMapping("/getInterestCount/{invest}/{yearRate}/{totalmonth}/{returnMethod}")
    public R getInterestCount(
            @PathVariable("invest") BigDecimal invest,

            @PathVariable("yearRate")BigDecimal yearRate,

            @PathVariable("totalmonth")Integer totalmonth,

            @PathVariable("returnMethod")Integer returnMethod) {

        BigDecimal  interestCount = lendService.getInterestCount(invest, yearRate, totalmonth, returnMethod);
        return R.ok().data("interestCount", interestCount);
    }


}
